<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- jsp文件头和头部 -->
<%@ include file="../../system/main/main_top.jsp"%>

<!-- 引入 -->
<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
<script type="text/javascript" src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->

<!--引入弹窗组件start-->
<script type="text/javascript" src="plugins/attention/zDialog/zDrag.js"></script>
<script type="text/javascript" src="plugins/attention/zDialog/zDialog.js"></script>
<!--引入弹窗组件end-->

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<!-- 引入 -->

<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
</head>
<body>
	<div class="container-fluid" id="main-container">
		<div id="page-content" class="clearfix">
			<div class="row-fluid">
				<div class="row-fluid">
					<!-- 检索  -->
					<form action="commercial/msgpush/list.do" method="post" name="Form" id="Form">
						<table>
							<tr>
								<td><span class="input-icon"> <input
										autocomplete="off" id="nav-search-input" type="text"
										name="keyword" value="${pd.keyword}" placeholder="这里输入关键词" />
										<i id="nav-search-icon" class="icon-search"></i>
								</span></td>
								<td style="vertical-align: top;"><button
										class="btn btn-mini btn-light" onclick="search();" title="检索">
										<i id="nav-search-icon" class="icon-search"></i>
									</button></td>
							</tr>
						</table>
						<!-- 检索  -->

						<table id="table_report"
							class="table table-striped table-bordered table-hover">
							<thead>
								<tr>
									<th class="center"><label><input type="checkbox"
											id="zcheckbox" /><span class="lbl"></span></label></th>
									<th>手机号码</th>
									<th>昵称</th>
									<th>性别</th>
									<th>平台等级</th>
									<th>是否启用</th>
									<th>是否锁定</th>
									<th>注册时间</th>
									<th>登录时间</th>
									<th>礼物总数</th>
									<th class="center">操作</th>
								</tr>
							</thead>

							<tbody>
								<!-- 开始循环 -->
								<c:choose>
									<c:when test="${not empty varList}">
										<c:forEach items="${varList}" var="var" varStatus="vs">
											<tr>
												<td class='center' style="width: 30px;"><label><input
														type='checkbox' name='ids' value="${var.m_id }"
														id="${var.m_id }" alt="${var.username }" /><span
														class="lbl"></span></label></td>
												<td>${var.mobile}</td>
												<td>${var.username}</td>
												<td><c:choose>
														<c:when test="${var.gender == 1 }">
															男
														</c:when>
														<c:otherwise>
															女
														</c:otherwise>
													</c:choose></td>
												<td>${var.member_rank_sys}</td>
												<td><c:choose>
														<c:when test="${var.is_enabled eq true }">
															启用
														</c:when>
														<c:otherwise>
															未启用
														</c:otherwise>
													</c:choose></td>
												<td><c:choose>
														<c:when test="${var.is_locked eq true }">
															锁定
														</c:when>
														<c:otherwise>
															未锁定
														</c:otherwise>
													</c:choose></td>
												<td><fmt:formatDate value="${var.create_date}"
														pattern="yyyy-MM-dd hh:mm:ss" /></td>
												<td><fmt:formatDate value="${var.login_date}"
														pattern="yyyy-MM-dd hh:mm:ss" /></td>
												<td>${var.gift_total}</td>
												<td style="width: 60px;" class="center">
													<div>
														<a title="推送" class="btn btn-small btn-success" onclick="has(1, '${var.m_id}', '');">推送</a>
													</div>
												</td>
											</tr>
										</c:forEach>
									</c:when>
									<c:otherwise>
										<tr class="main_info">
											<td colspan="100" class="center">没有相关数据</td>
										</tr>
									</c:otherwise>
								</c:choose>
							</tbody>
						</table>

						<div class="page-header position-relative">
							<table style="width: 100%;">
								<tr>
									<td style="vertical-align: top;">
										<a title="推送全部" class="btn btn-small btn-success" onclick="has(3,'','');">推送全部</a>
										<a title="批量推送" class="btn btn-small btn-success" onclick="has(2,'','确定要给选中的Meet用户推送消息吗?');">批量推送</a>
									</td>
									<td style="vertical-align: top;"><div class="pagination"
											style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}</div></td>
								</tr>
							</table>
						</div>
					</form>
				</div>

				<!-- PAGE CONTENT ENDS HERE -->
			</div>
			<!--/row-->

		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->

	<!-- 返回顶部  -->
	<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse"> <i
		class="icon-double-angle-up icon-only"></i>
	</a>

	<!-- 引入 -->
	<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
	<script src="static/js/bootstrap.min.js"></script>
	<script src="static/js/ace-elements.min.js"></script>
	<script src="static/js/ace.min.js"></script>
	<!-- 引入 -->

	<script type="text/javascript">
		$(top.hangge());
		
		//检索
		function search(){
			top.jzts();
			$("#Form").submit();
		}
		
		//推送单个
		function push(Id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="推送";
			 diag.URL = '<%=basePath%>/commercial/msgpush/pushSingle.do?m_id='+Id;
			 diag.Width = 300;
			 diag.Height = 360;
			 diag.CancelEvent = function(){ //关闭事件
				if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					 nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//推送选中的
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					var emstr = '';
					var phones = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  	
						  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
						  	else emstr += ';' + document.getElementsByName('ids')[i].id;
						  	
						  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
						  	else phones += ';' + document.getElementsByName('ids')[i].alt;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要给选中的Meet用户推送消息吗?'){
							top.jzts();
						 	var diag = new top.Dialog();
						 	diag.Drag=true;
							diag.Title ="新增";
							diag.URL = 'commercial/msgpush/pushChooseUser.do?m_ids=' + str;
							diag.Width = 300;
							diag.Height = 360;
							diag.CancelEvent = function(){ //关闭事件
								if('${page.currentPage}' == '0'){
									top.jzts();
									setTimeout("self.location=self.location",100);
								}else{
									nextPage(${page.currentPage});
								}
								diag.close();
							};
							diag.show();
						}
					}
				}
			});
		}
		
		//推送全部
		function pushAll(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>/commercial/msgpush/pushAll.do';
			 diag.Width = 300;
			 diag.Height = 360;
			 diag.CancelEvent = function(){ //关闭事件
				 if('${page.currentPage}' == '0'){
					 top.jzts();
					 setTimeout("self.location=self.location",100);
				 }else{
					 nextPage(${page.currentPage});
				 }
				diag.close();
			 };
			 diag.show();
		}
		
		//判断编码是否存在
		function has(pushSope, Id, msg){
			$.ajax({
				type : "PUT",
				url : "commercial/msgpush/membershas"+ ".json",
				//data:JSON.stringify(dicvalue),
				contentType:"application/json",  //发送至服务器的类型
				//dataType : "json",     //预期服务器返回类型
				success: function(data){
					//alert(data.string);
					//return false;
					if(data.string=="error"){
						alert("还未绑定Meet账号，不能推送系统消息，请先绑定！");
						return false;
					}else{
						if(pushSope == 1){
							push(Id);
						}else if(pushSope == 2){
							makeAll(msg);
						}else{
							pushAll();
						}
					}
				}
			})
		}
		
		//复选框
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});
		</script>
</body>
</html>

